<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>js导航栏</title>
    <style>
        *{margin: 0; padding: 0;}
        #wrapper {
            width: 900px;
            margin: 100px auto 0;
            background-color: beige;
        }
        #nav {
            list-style: none;
            height: 50px;
            
        }
        #nav li {
            float: left;
            width: 120px;
            line-height: 50px;
            font-size: larger;
            text-align: center;
        }
        #nav li.current {
            background-color: red;
            transition: 1s ease-in;
        }
        #nav li a {
            text-decoration: none;
        }
    </style>
</head>
<body>
    <div id="wrapper">
        <ul id="nav">
            <li class="current"><a href="#">首页</a></li>
            <li><a href="#">HTML</a></li>
            <li><a href="#">CSS</a></li>
            <li><a href="#">JavaScript</a></li>
            <li><a href="#">jQuery</a></li>
            <li><a href="#">Node.js</a></li>
            <li><a href="#">About</a></li>
        </ul>
    </div>
    <script>
        //取出所有的li元素
        var oLi = document.getElementById('nav').getElementsByTagName('li');
        //遍历循环所有的li
        for(var i =0;i < oLi.length;i ++) {
            var aObjs = oLi[i].firstElementChild;
            aObjs.onmouseover = function(){
                for(var j = 0;j < oLi.length;j ++){
                    oLi[j].removeAttribute('class');
                }
                this.parentNode.className = "current";
            }
        }
    </script>
</body>
</html>